package hust.att2.fragment;

import hust.att2.adapter.ImageAdapter;
import hust.att2.movieticketing.DetailFilmActivity;
import hust.att2.movieticketing.R;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;

public final class HotFilmFragment extends Fragment {
	private static final String KEY_CONTENT = "TestFragment:Content";
	private GridView gridView;
	static final String[] MOBILE_OS = new String[] { "f1", "f2", "f3", "f4",
			"f5", "f6", "f7", "f8", "f9", "f10" };

	public static HotFilmFragment newInstance(String content) {
		HotFilmFragment fragment = new HotFilmFragment();
		return fragment;
	}

	private String mContent = "???";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		if ((savedInstanceState != null)
				&& savedInstanceState.containsKey(KEY_CONTENT)) {
			mContent = savedInstanceState.getString(KEY_CONTENT);
		}

	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		container = (ViewGroup) inflater.inflate(
				R.layout.playing_fragment_layout, null);

		return container;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);

		gridView = (GridView) this.getView().findViewById(R.id.gridView1);
		gridView.setAdapter(new ImageAdapter(getActivity(), MOBILE_OS));

		gridView.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View v,
					int position, long id) {
				Toast.makeText(getActivity(),
						((TextView) v.findViewById(R.id.tv_name)).getText(),
						Toast.LENGTH_SHORT).show();
				Intent i = new Intent(getActivity(), DetailFilmActivity.class);
				getActivity().startActivity(i);
			}
		});
	}

	@Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		outState.putString(KEY_CONTENT, mContent);
	}
}
